<html>
<head><meta charset="utf-8"><title>collecting RA data into postgres · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html">collecting RA data into postgres</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225065024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225065024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225065024">(Feb 03 2021 at 19:07)</a>:</h4>
<p>Hello!</p>
<p>I was recently looking at <a href="https://source.chromium.org/">https://source.chromium.org/</a> and i thought it would be cool to have a rust version of something like that, i wanted to experiment just for fun. However, i am not quite sure how i would go about loading a crate from the file system with RA and then getting info like variables, modules, structs, etc from it. What structures/crates should i use? i look at <code>ra_ap_hir</code> and <code>ra_ap_ide</code> but i am a bit confused on:</p>
<ul>
<li>ide defines things like reference search results but i could not find any place to actually ask for it</li>
<li>what is the actual initial procedure for loading a crate?</li>
</ul>



<a name="225065736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225065736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225065736">(Feb 03 2021 at 19:12)</a>:</h4>
<p>you probably mostly want the API of the hir crate. The code of the <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/cli/analysis_stats.rs">analysis-stats command</a> should give some pointers</p>



<a name="225065887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225065887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225065887">(Feb 03 2021 at 19:13)</a>:</h4>
<p>Cool, ill look through that. I looked through hir already but was a bit confused on how to get the data that the ide crate gets. I think looking at the ide crate source code should help</p>



<a name="225073385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225073385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225073385">(Feb 03 2021 at 20:04)</a>:</h4>
<p>Since RA keeps a DB of basically everything is it possible to just serialize that entire db then load it back at a later date? or would that be way too much info to store efficiently?</p>



<a name="225073693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225073693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225073693">(Feb 03 2021 at 20:06)</a>:</h4>
<p>That would require everything stored in it to be serializable</p>



<a name="225073725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225073725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225073725">(Feb 03 2021 at 20:06)</a>:</h4>
<p>I don't think it's really supported by salsa either</p>



<a name="225073799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225073799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225073799">(Feb 03 2021 at 20:07)</a>:</h4>
<p>I see, because to do this i need to keep a database of things like every variable in a file, its type, its definition location, etc</p>



<a name="225073891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225073891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225073891">(Feb 03 2021 at 20:07)</a>:</h4>
<p>RA doesn't really keep a full database of all that information. it's lazily computed, so you've got to ask for it before it's in the DB</p>



<a name="225073968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225073968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225073968">(Feb 03 2021 at 20:08)</a>:</h4>
<p>oh right <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="225074220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225074220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225074220">(Feb 03 2021 at 20:10)</a>:</h4>
<p>theoretically it should be possible to store and reload the DB to reduce startup times; that's how rustc incremental compilation works. as Jonas wrote, it'd require everything to be serializable and salsa support though</p>



<a name="225074484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225074484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225074484">(Feb 03 2021 at 20:12)</a>:</h4>
<p>I see, then i think ill just do it the brute force way and have a program to call RA and load the data into postgres. How would i go about crawling every file and getting stuff like the variables in there, etc?</p>



<a name="225082324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225082324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> detrumi <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225082324">(Feb 03 2021 at 21:09)</a>:</h4>
<p>analysis-stats already loops over items, so you can pattern match all the way down</p>



<a name="225083186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225083186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225083186">(Feb 03 2021 at 21:15)</a>:</h4>
<p>Yeah getting items seems super easy, but i cant find a way of getting defined variables :/</p>



<a name="225083670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225083670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225083670">(Feb 03 2021 at 21:18)</a>:</h4>
<p>it's a bit obscure, but maybe this <code>From</code> impl helps? <a href="https://rust-analyzer.github.io/rust-analyzer/hir/struct.Local.html#impl-From%3C(DefWithBodyId%2C%20Idx%3CPat%3E)%3E">https://rust-analyzer.github.io/rust-analyzer/hir/struct.Local.html#impl-From%3C(DefWithBodyId%2C%20Idx%3CPat%3E)%3E</a></p>



<a name="225083779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225083779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225083779">(Feb 03 2021 at 21:19)</a>:</h4>
<p>isnt this only for functions, statics, and consts?</p>



<a name="225083957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/collecting%20RA%20data%20into%20postgres/near/225083957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/collecting.20RA.20data.20into.20postgres.html#225083957">(Feb 03 2021 at 21:20)</a>:</h4>
<p>Oh i see what you mean</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>